/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.geom.Dimension;
import org.aswing.JLabel;
import org.aswing.JPanel;

import fever.app.local.LocalisationEvent;
import fever.utils.DateUtils;

import fvaswing.components.reader.abstract.FvPlayList;
import fvaswing.components.reader.paper.FvPaperItem;
import fvaswing.components.reader.video.FvVideoItem;

/**
 * {@link fvaswing.components.reader.FvVideoPlayer} playlist
 *
 * @author Romain Ecarnot
 */
class fvaswing.components.reader.video.FvVideoList extends FvPlayList
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
		
	private var _sizeLabel : JLabel;
	private var _sizeInput : JLabel;	private var _durationLabel : JLabel;	private var _durationInput : JLabel;
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * @param name Playlist name
	 * @param enabledExternalLoading Allow user to load external file
	 */
	public function FvVideoList( name : String, enabledExternalLoading : Boolean )
	{
		super( name, enabledExternalLoading );
	}
	
	/**
	 * Triggered when Localisation language change.
	 */
	public function onLocalisationUpdate( event : LocalisationEvent ) : Void
	{
		super.onLocalisationUpdate( event );
		
		_frame.setTitle( _resources.videoTitle );
		_sizeLabel.setText( _resources.videoSize );			_durationLabel.setText( _resources.videoDuration );	
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	private function _createInfoPanel() : JPanel
	{
		var p : JPanel = super._createInfoPanel();
		
		_sizeLabel = _createLabel( _resources.videoSize );
		_sizeInput = new JLabel( "-", JLabel.LEFT );
		
		_durationLabel = _createLabel( _resources.videoDuration );
		_durationInput = new JLabel( "-", JLabel.LEFT );
				p.append( _createLine( _sizeLabel, _sizeInput ) );		p.append( _createLine( _durationLabel, _durationInput ) );
		return p;
	}
	
	private function _updateInformations( item : FvVideoItem ) : Void
	{
		super._updateInformations( item );
		
		var size : Dimension = item.getSize();
		if( size ) _sizeInput.setText( size.width + "x" + size.height );
		else _sizeInput.setText( "-" );
		
		if( item.getDuration() != undefined )
			_durationInput.setText( DateUtils.seconde2time( item.getDuration() ) + " s" );
		else _durationInput.setText( "-" );
	}
	
	/**
	 * Overrides for custom item type.
	 */
	private function _buildNewItemInstance( o : Object ) : FvPaperItem
	{
		var item : FvPaperItem = new FvPaperItem( o.url, o.title, o.page );
		return item;
	}
}